﻿using CsvHelper;
using System.Globalization;

namespace DataProcessor;
public sealed class DataReader
{
    private readonly DirectoryInfo directory;
    public DataReader(DirectoryInfo directory)
    {
        this.directory = directory;
    }

    public IEnumerable<(double Ch1, double Ch2)> Read(
        int sample, int frequency, int division)
    {
        var path = Path.Combine(this.directory.FullName, $"{sample}-{frequency}-{division}.CSV");
        using var reader = new StreamReader(path);
        using var csv = new CsvReader(reader, CultureInfo.InvariantCulture);

        _ = csv.Read();
        _ = csv.Read();

        while (csv.Read())
        {
            var ch1 = csv.GetField<double>(1);
            var ch2 = csv.GetField<double>(2);
            yield return (ch1, ch2);
        }
    }
}
